package jmine.tec.report.impl.table;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.PropertyUtils;

/**
 * Implementação padrão de resolver de propriedade, delega a implementação para PropertyUtils.
 * 
 * @see org.apache.commons.beanutils.PropertyUtils
 * @author lundberg
 * @param <V>
 */
public class PropertyCellValueResolver<V> implements CellValueResolver<V>, Serializable {

    private final String property;

    /**
     * Construtor
     * 
     * @param property property
     */
    public PropertyCellValueResolver(String property) {
        this.property = property;
    }

    /**
     * {@inheritDoc}
     */
    public Object resolveCellValue(V value) {
        try {
            return PropertyUtils.getProperty(value, this.property);
        } catch (IllegalAccessException e) {
            throw new IllegalStateException(e);
        } catch (InvocationTargetException e) {
            throw new IllegalStateException(e);
        } catch (NoSuchMethodException e) {
            throw new IllegalStateException(e);
        }
    }
}
